<?php
require 'Model.php';
	class MusicModel extends Model{
		function __Construct(){
			parent::__Construct();
			$this->mod = 'musics';
		}
		function getList(){
			$sql = "select * from {$this->mod}";
		    $data = $this->conn->query($sql);
			return $data;
		}

		function add($data){
			if(!empty($_FILES["url"]["name"])){
  				$url = $this->uploadfile('url','./upload/',array('mp3'));
  				}
			  else{
			  	$url='';
			  }

			  $music = array(
					'song' => trim($data['song']),  
					'gid' => $data['singer'],
					'url'=>$url
			  	);
			  $keys = implode(',',array_keys($music));
			  $values = implode("','", array_values($music));
			  $sql="insert into {$this->mod} ({$keys}) VALUES ('{$values}')";
			  //执行SQL语句
				$result = $this->conn->query($sql);
					return $result;
			  
		}



		function delmusic($id){
			$sql = "delete from {$this->mod} where sid=".$id;
			$result = $this->conn->query($sql);
			return $result;
		}
			function getsinger(){
			$sql = "select * from singers";
		    $data = $this->conn->query($sql);
			return $data;
		}
				function addsinger($data){
			if(!empty($_FILES["pic"]["name"])){
  				$pic = $this->uploadfile('pic','./upload/',array('jpg','gif','png'));
  				}
			  else{
			  	$pic='';
			  }

			  $singer = array(
					'gname' => trim($data['gname']),  
					'pic'=>$pic,
					'intro' => $data['intro']
			  	);
			  $keys = implode(',',array_keys($singer));
			  $values = implode("','", array_values($singer));
			  $sql="insert into  singers({$keys}) VALUES ('{$values}')";
			  //执行SQL语句
			$result = $this->conn->query($sql);
               return $result;
			  
		}
		function delsinger($id){
			$sql = "delete from {$this->mod} where gid=".$id;
			$result = $this->conn->query($sql);
			return $result;
		}
	}
?>